package com.three.controller;

import com.baor.baseUtil.R;
import com.three.domain.Projectmembers;
import com.three.domain.Projects;
import com.three.domain.Subprojects;
import com.three.domain.Tasks;
import com.three.service.ProjectsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class ProjectsController {
    @Autowired
    private ProjectsService projectsService;
    @RequestMapping(value = "/projectsList")
    public R projectsList(@RequestBody Map<String, Object> map) {
        String keyword = (String) map.get("keyword");
        String start_date = (String) map.get("start_date");
        String end_date = (String) map.get("end_date");
        Integer pageIndex = (Integer) map.get("pageIndex");
        Integer pageSize = (Integer) map.get("pageSize");
        return projectsService.projectsList(keyword, start_date, end_date, pageIndex, pageSize);
    }
    @RequestMapping(value = "/addProjects")
    public R addProjects(@RequestBody Projects projects) {
        return projectsService.addProjects(projects);
    }

    @RequestMapping(value = "/tasksList")
    public R tasksList(@RequestBody Map<String, Object> map) {
        String keyword = (String) map.get("keyword");
        String start_date = (String) map.get("start_date");
        String end_date = (String) map.get("end_date");
        Integer pageIndex = (Integer) map.get("pageIndex");
        Integer pageSize = (Integer) map.get("pageSize");
        Integer project_id = (Integer) map.get("project_id");
        Integer subproject_id = (Integer) map.get("subproject_id");
        return projectsService.tasksList(keyword, start_date, end_date, pageIndex, pageSize, project_id, subproject_id);
    }
    //添加任务
    @RequestMapping(value = "/addTasks")
    public R addTasks(@RequestBody Tasks tasks) {
        return projectsService.addTasks(tasks);
    }
    @RequestMapping(value = "/updateTasks")
    public R updateTasks(@RequestBody Tasks tasks) {
        return projectsService.updateTasks(tasks);
    }
    @RequestMapping(value = "/deleteTasks")
    public R deleteTasks(@RequestBody Tasks tasks) {
        return projectsService.deleteTasks(tasks.getTask_id(), tasks.getSubproject_id(), tasks.getProject_id());
    }

    @RequestMapping(value = "/projectmembersList")
    public R projectmembersList(@RequestBody Map<String,Object> map) {
        Integer project_id = (Integer) map.get("project_id");
        return projectsService.projectmembersList(project_id);
    }

    @RequestMapping(value = "/notInProjectmembers")
    public R notInProjectmembers() {
        return projectsService.notInProjectmembers();
    }
//添加项目组成员
    @RequestMapping(value = "/addProjectmembers")
    public R addProjectmembers(@RequestBody List<Projectmembers> projectMembers) {
        return projectsService.addProjectmembers(projectMembers);
    }


    @RequestMapping(value = "/projectsListByTeacher")
    public Object projectsListByTeacher(@RequestBody Map<String,Object> map) {
        return projectsService.projectsListByTeacher(map);
    }

    @RequestMapping(value = "/subprojectsList")
    public Object subprojectsList(@RequestBody Map<String,Object> map) {
        Integer project_id = (Integer) map.get("project_id");
        Integer pageIndex = (Integer) map.get("pageIndex");
        Integer pageSize = (Integer) map.get("pageSize");
        return projectsService.subprojectsList(project_id, pageIndex, pageSize);
    }

    @RequestMapping(value = "/addSubprojects")
    public Object addSubprojects(@RequestBody Subprojects subprojects) {
        return projectsService.addSubprojects(subprojects);
    }

    @RequestMapping(value = "/updateTasksByStudent")
    public Object updateTasksByStudent(@RequestBody Tasks tasks) {
        return projectsService.updateTasksByStudent(tasks);
    }
}
